package com.hxkj.cst.chengshuitong.base

import android.os.Build
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.WindowManager
import kotlinx.android.synthetic.main.include_toolbar.*

/**
 * 作者： Luoyang on 2017/5/25.
 * 描述： 提供Toolbar代码复用和Title设置
 */
abstract class BaseActivity<T : BasePresenter> : AppCompatActivity() {
    var mPresenter: T? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(provideContentView())

        createPresenter()?.let { mPresenter = it }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        }
        setSupportActionBar(toolbar)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        supportActionBar?.setDisplayShowTitleEnabled(false)
    }

    abstract fun provideContentView(): Int

    open fun createPresenter(): T? = null

    override fun onSupportNavigateUp(): Boolean {
        onBackPressed()
        return super.onSupportNavigateUp()
    }

    fun setToolbarTitle(toolbarTitle: String) {
        toolbar_title.text = toolbarTitle
    }
}

